package cn.nfwx.tv.manager;

import android.content.Context;

import java.util.HashMap;
import java.util.Map;

import cn.nfwx.tv.callback.ResponseListener;
import cn.nfwx.tv.okhttp.CustomOkHttpClient;
import cn.nfwx.tv.okhttp.UrlHelper;
import cn.nfwx.tv.util.LogUtil;
import cn.nfwx.tv.util.SharePrefUtil;
import okhttp3.Callback;

/**
 * Created by zhouzechao on 2017/12/7.
 */

public class SearchManager {

    /**
     * 查询对应的栏目
     *
     * @param context
     * @param key
     * @param pageNo
     * @param pageSize
     * @param callBack
     * @return
     */
    public static String requestColumnSearchResult(Context context, String key, int pageNo, int pageSize, ResponseListener callBack) {
        String request_tag = "requestColumnSearchResult";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getColumnListUrl(key, pageNo, pageSize);
        CustomOkHttpClient.postObjectRequest(context, url, request_tag, callBack);
        return request_tag;
    }

    /**
     * 查询对应的视频
     *
     * @param context
     * @param key
     * @param pageNo
     * @param pageSize
     * @param callBack
     * @return
     */
    public static String requestVodSearchResult(Context context, String key, int pageNo, int pageSize, ResponseListener callBack) {
        String request_tag = "requestVodSearchResult";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getColumnDetailUrl(key, pageNo, pageSize);
        CustomOkHttpClient.postObjectRequest(context, url, request_tag, callBack);
        return request_tag;
    }

    /**
     * 添加关键字
     *
     * @param context
     * @param keyword
     * @param callBack
     * @return
     */
    public static String requestAddKeywordResult(Context context, String keyword, ResponseListener callBack) {
        String request_tag = "requestAddKeywordResult";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getAddSearchUrl();
        Map<String, String> postMap = new HashMap<String, String>();
        postMap.put("keyword", keyword);
        CustomOkHttpClient.postObjectRequestWithHeader(context, url, postMap, request_tag, SharePrefUtil.getAccessToken(context), callBack);
        return request_tag;
    }


    /**
     * 获取热门搜索
     *
     * @param context
     * @param count
     * @param callBack
     * @return
     */
    public static String requestHotKeywordResult(Context context, int count, Callback callBack) {
        String request_tag = "requestHotKeywordResult";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getHotKeywordUrl(count);
        CustomOkHttpClient.doGet(url, request_tag, callBack);
        return request_tag;
    }

    /**
     * 热门关键字
     *
     * @param context
     * @param responseListener
     * @return
     */
    public static String requestIjkHotKeyword(Context context, ResponseListener responseListener) {
        String request_tag = "requestIjkHotKeyword";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getIjkKeywordsUrl();
        CustomOkHttpClient.getObjectRequest(context, url, request_tag, responseListener);
        return request_tag;
    }

    /**
     * 搜索关键字
     *
     * @param context
     * @param responseListener
     * @return
     */
    public static String requestIjkSearchResult(Context context, String keywork, ResponseListener responseListener) {
        String request_tag = "requestIjkSearch";
        CustomOkHttpClient.cancleAll(request_tag);
        String url = UrlHelper.getIjkSearchResultUrl(keywork);
        CustomOkHttpClient.getObjectRequest(context, url, request_tag, responseListener);
        return request_tag;
    }
}
